<?php
/**
 * Created by PhpStorm.
 * User: zeopean
 * Date: 2015/8/12
 * Time: 9:40
 */
namespace App\Exceptions;

use Exception;

class ProjectException extends Exception
{
    /**
     * ProjectNameExists        项目名字已经存在
     * PhoneIsError             联系方式错误
     * NewsTitleExists          新闻标题已经存在
     */

    const ProjectNameExists     = 0x01 ;
    const PhoneIsError          = 0x02 ;
    const NewsTitleExists       = 0x03 ;
    const CreateProjectFirst    = 0x04;

    public function __construct($code, array $data = [], Exception $previous = null)
    {
        switch ($code) {
            case self::ProjectNameExists:
                $message = trans('exception.project.project_name_exists', ['project_name' => array_get($data, 'project_name')]);
                break;
            case self::PhoneIsError:
                $message = trans('exception.project.phone_is_error', ['phone' => array_get($data, 'phone')]);
                break;
            case self::NewsTitleExists:
                $message = trans('exception.project_news.news_title_exists', ['news_title' => array_get($data, 'news_title')]);
                break;
            case self::CreateProjectFirst:
                $message = trans('exception.project_create_first',[]);
                break;
            default:
                $message = trans('general.unknown_exception');
                break;
        }

        parent::__construct($message, $code, $previous);
    }
}